package com.woniuxy.service.impl;

import com.woniuxy.entity.ShopCategories;
import com.woniuxy.dao.ShopCategoriesDao;
import com.woniuxy.service.ShopCategoriesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;


/**
 * (ShopCategories)表服务实现类
 *
 * @author makejava
 * @since 2025-07-10 11:54:12
 */
@Service("shopCategoriesService")
public class ShopCategoriesServiceImpl implements ShopCategoriesService {
    @Autowired
    private ShopCategoriesDao shopCategoriesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ShopCategories queryById(Long id) {
        return this.shopCategoriesDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param shopCategories 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ShopCategories> queryByPage(ShopCategories shopCategories, PageRequest pageRequest) {
        long total = this.shopCategoriesDao.count(shopCategories);
        return new PageImpl<>(this.shopCategoriesDao.queryAllByLimit(shopCategories, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param shopCategories 实例对象
     * @return 实例对象
     */
    @Override
    public ShopCategories insert(ShopCategories shopCategories) {
        this.shopCategoriesDao.insert(shopCategories);
        return shopCategories;
    }

    /**
     * 修改数据
     *
     * @param shopCategories 实例对象
     * @return 实例对象
     */
    @Override
    public ShopCategories update(ShopCategories shopCategories) {
        this.shopCategoriesDao.update(shopCategories);
        return this.queryById(shopCategories.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.shopCategoriesDao.deleteById(id) > 0;
    }
}
